package com.alm.handle.core.domain.entity.rs;

import com.alm.handle.util.ELeCurrentUtil;
import lombok.Data;

import java.math.BigDecimal;

@Data
public class GetWayUpEleDataRS {
    private BigDecimal voltage ;

    private Integer  relayStatus;

    private Integer  workStatus;

    private BigDecimal  electricCurrent;

    private BigDecimal  powerFactor;

    private BigDecimal  activePower;

    private Integer  netWorkType;

    private String devId;

    private String getWayMac;

    private Long updateTime;
    public void computeData(){
        if(this.voltage!=null){
            this.voltage= this.voltage.divide(ELeCurrentUtil.One_Hundred).setScale(4,BigDecimal.ROUND_DOWN);
        }
        if(this.electricCurrent!=null){
            this.electricCurrent=this.electricCurrent.divide(ELeCurrentUtil.Thousand).setScale(4,BigDecimal.ROUND_DOWN);
        }
        if(this.powerFactor!=null){
            this.powerFactor=this.powerFactor.divide(ELeCurrentUtil.One_Hundred).setScale(4,BigDecimal.ROUND_DOWN);
        }
        if(this.activePower!=null){
            this.activePower= this.activePower.divide(ELeCurrentUtil.Thousand).setScale(4,BigDecimal.ROUND_DOWN);
        }
        if (this.electricCurrent != null && this.activePower != null) {
            if (this.electricCurrent.doubleValue() > 0.01 || this.activePower.doubleValue() > 1.0) {
                this.workStatus = 1;
            }

            if (this.electricCurrent.doubleValue() == 0.0 || this.activePower.doubleValue() < 0.02) {
                this.workStatus = 0;
            }
        }
    }
}
